'''
封装所有接口
'''
import requests
import json

from icecream import ic

from Common.basic_api import env_translation

class APICilent:

    def __init__(self):
        self.base_url=env_translation.env_translation()
        self.header = {'Content-Type': 'application/json'}

    def department_query(self,query_data:str = None)->dict:
        url = f"{self.base_url}/api/departments/"
        #查全部学院
        if query_data is None or query_data == '':
            response=requests.get(url,headers=self.header)
            return response.json()
        #查指定学院
        elif query_data is not None:
            response=requests.get(url=url+query_data,headers=self.header)
            return response.json()
        else:
            raise ValueError("Invalid type value. Must be one of query or delete.")



    def department_add(self,add_data:dict):
        url = f"{self.base_url}/api/departments/"
        response=requests.post(url,json=add_data,headers=self.header)
        return response.status_code,response.json()


if __name__ == '__main__':
    ic(APICilent().department_query())